package com.bjb.vr.remote.ws.rabbitmq.config;

import com.bjb.vr.remote.ws.rabbitmq.constants.RabbitmqConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

@Configuration
@DependsOn("ipConfiguration")
public class RabbitmqConfig {

    @Autowired
    IpConfiguration ipConfiguration;

    @Bean
    public Queue fanoutQueue() {
        String queueName = ipConfiguration.getIp() + "." +ipConfiguration.getPort();
        return new Queue(queueName, false);
    }


    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(RabbitmqConstants.FANOUT_WEBSOCKET_EXCHANGE, false, false);
    }



    @Bean
    public Binding bindFanoutQueue() {
        return BindingBuilder.bind(fanoutQueue()).to(fanoutExchange());
    }

}
